package com.tensquare.search.config;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

/**
 * @author fangyu
 * @version v1.0.0
 * @date 2020/10/14 11:35 上午
 */
@Configuration
public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {

    /**
     * elasticsearch集群地址
     */
    @Value("${es.ip}")
    private String ip;

    /**
     * 端口
     */
    @Value("${es.port}")
    private String port;

    @Bean
    @Override
    public RestHighLevelClient elasticsearchClient() {
        System.out.println(ip+port);
        ClientConfiguration configuration = ClientConfiguration.builder()
                .connectedTo(ip + ":" + port)
                .build();
        return RestClients.create(configuration).rest();
    }
}
